﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace Demo
{
    public partial class freezeRowsCols : DemoBaseUserControl
    {
        public freezeRowsCols()
        {
            InitializeComponent();
            this.Title = "冻结行列";
            this.Description = "Spread .NET  可以冻结任意数目的行和列，冻结的行总是在最上边，冻结的列总是在最左边。设置下面的选项来冻结行和列，然后滚动可以看到效果。为了显示效果，本例中把冻结的区域背景色改为了灰色。";
        }

        private void freezeRowsCols_Load(object sender, EventArgs e)
        {

            //销售数据清单DataSet dataset = new 销售数据清单DataSet();
            FpSpread1.DataSource = 销售明细表TableAdapter.GetData();

            this.FpSpread1_Sheet1.ColumnCount = 15;
            this.FpSpread1.Sheets[0].FrozenColumnCount = 1;
            this.FpSpread1.Sheets[0].FrozenRowCount = 1;

            FarPoint.Win.ComplexBorderSide borderStyle = new FarPoint.Win.ComplexBorderSide(Color.Black, 1);
            this.FpSpread1_Sheet1.Columns[0].Border = new FarPoint.Win.ComplexBorder(null, null, borderStyle, null);
            this.FpSpread1_Sheet1.Rows[0].Border = new FarPoint.Win.ComplexBorder(null, null, null, borderStyle);

            this.cbRow.SelectedIndex = 1;
            this.cbCol.SelectedIndex = 1;

        }

        private void cbCol_SelectedIndexChanged(object sender, EventArgs e)
        {
            FarPoint.Win.ComplexBorderSide borderStyle = new FarPoint.Win.ComplexBorderSide(Color.Black, 1);
            if ((cbCol.SelectedItem.ToString() == ""))
            {
                return;
            }
            // Freeze from scrolling
            FpSpread1.Sheets[0].FrozenColumnCount = Convert.ToInt32(cbCol.SelectedItem);
            FpSpread1.Sheets[0].Columns[0, (FpSpread1.Sheets[0].ColumnCount - 1)].ResetBorder();
            int col2 = Convert.ToInt32(cbCol.SelectedItem);
            if ((col2 > 0))
            {
                this.FpSpread1_Sheet1.Columns[col2 - 1].Border = new FarPoint.Win.ComplexBorder(null, null, borderStyle, null);

            }
        }

        private void cbRow_SelectedIndexChanged(object sender, EventArgs e)
        {
            FarPoint.Win.ComplexBorderSide borderStyle = new FarPoint.Win.ComplexBorderSide(Color.Black, 1);
            if ((cbRow.SelectedItem.ToString() == ""))
            {
                return;
            }
            // Freeze from scrolling
            FpSpread1.Sheets[0].FrozenRowCount = Convert.ToInt32(cbRow.SelectedItem.ToString());
            FpSpread1.Sheets[0].Rows[0, FpSpread1.Sheets[0].RowCount - 1].ResetBorder();
            int row2 = Convert.ToInt32(cbRow.SelectedItem.ToString());
            if ((row2 > 0))
            {
                this.FpSpread1_Sheet1.Rows[row2 - 1].Border = new FarPoint.Win.ComplexBorder(null, null, null, borderStyle);
            }
        }

    }
}
